package com.yuan.chatrobot.tulingRobot;

import cn.hutool.core.lang.Console;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 小源同学
 * @Date 2021 12 17 00 09
 * @Describe Please describe the role of this class
 **/
public class Robot {
    private String url;
    private String apiKey;
    private String userId;


    public Robot() {
    }

    public Robot(String url, String apiKey) {
        this.url = url;
        this.apiKey = apiKey;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    //处理请求信息
    private String before(String msg) {
        return "{'reqType':0,'perception':{'inputText':{'text':" + msg + "},'selfInfo':{'location':{'city':\"北京\",'province':\"北京\",'street':\"信息路\"}}},'userInfo':{'apiKey':" + this.getApiKey() + ",'userId':'" + this.getUserId() + "'}}";
    }

    //聊天
    public String Chat(String msg)   {
        JSONObject jsonObject = JSONUtil.parseObj(before(msg));
        String result2 = HttpRequest.post(this.getUrl()).body(jsonObject.toString()).timeout(20000).execute().body();
        return JSONUtil.parseObj(result2).get("results").toString(); //获取返回的结果信息
    }
}
